
/**
 * @description 将数组拆分为多个数组
 * @param {Array} arr 需要被拆分的数组
 * @param {number} step 拆分时的步长
 * @returns
 */
export const group = (arr, step) => {
  let index = 0
  const newArr = []
  while (index < arr.length){
    newArr.push(arr.slice(index, index += step))
  }
  return newArr
}

export const throttle = (fn, wait) => {
  let timer = null
  return function (...args){
    if (timer) return
    fn.apply(this, args)
    timer = setTimeout(() => {
      timer = null
    }, wait)
  }
}

export const debounce = (fn, wait) => {
  let timer = null
  return function (...args){
    if (timer) clearTimeout(timer)
    timer = setTimeout(() => {
      fn.apply(this, args)
    }, wait)
  }
}
export const sleep = (time) => new Promise(resolve => setTimeout(resolve, time))
